Attribute VB_Name = "basRAS"
'*---------------------------------------------------------------
'*
'* ModuleName:     basRAS
'* FileName:       RAS.BAS
'* Date:           July 1998
'* Author:         Ian M. Weatherburn
'* Company:        Mindkey Software Solutions (Pty) Ltd.
'* Copyright:      Copyright (C) 1998 by Mindkey Software Solutions
'*                 All Rights Reserved
'* Description:    Remote Access Server External API
'*
'*---------------------------------------------------------------

Option Explicit

'*---------------------------------------------------------------
'* Public Constants
'*---------------------------------------------------------------

' Connection Retry Count
Public Const RAS_RetryCount = 5

' LAN Manager API Constants
Public Const UNLEN = 256
Public Const PWLEN = 256
Public Const DNLEN = 15
Public Const NETBIOS_NAME_LEN = 16
Public Const MAX_PATH = 128

' Dial Notifier Public Types
Public Const RAS_NotifyWindowHandle = &HFFFFFFFF
Public Const RAS_NotifyDialFunc = &H0
Public Const RAS_NotifyDialFunc1 = &H1

' Remote Access API Constants
Public Const RAS_MaxDeviceType = 16
Public Const RAS_MaxPhoneNumber = 128
Public Const RAS_MaxIPAddress = 15
Public Const RAS_MaxIPXAddress = 21

Public Const RAS_MaxEntryName = 20
Public Const RAS_MaxDeviceName = 32
Public Const RAS_MaxCallbackNumber = 48

Public Const RAS95_MaxEntryName = 256
Public Const RAS95_MaxDeviceName = 128
Public Const RAS95_MaxCallbackNumber = RAS_MaxPhoneNumber

' Intermediate states to a connection
Public Const RASCS_PAUSED = &H1000&
Public Const RASCS_DONE = &H2000&

' Protocol code to projection data structure mapping
Public Const RASP_Amb = &H10000
Public Const RASP_PppNbf = &H803F&
Public Const RASP_PppIpx = &H802B&
Public Const RASP_PppIp = &H8021&
Public Const RASP_PppLcp = &HC021&
Public Const RASP_Slip = &H20000

' Intermediate states to a connection
Public Const RASCS_OpenPort = 0&
Public Const RASCS_PortOpened = 1&
Public Const RASCS_ConnectDevice = 2&
Public Const RASCS_DeviceConnected = 3&
Public Const RASCS_AllDevicesConnected = 4&
Public Const RASCS_Authenticate = 5&
Public Const RASCS_AuthNotify = 6&
Public Const RASCS_AuthRetry = 7&
Public Const RASCS_AuthCallback = 8&
Public Const RASCS_AuthChangePassword = 9&
Public Const RASCS_AuthProject = 10&
Public Const RASCS_AuthLinkSpeed = 11&
Public Const RASCS_AuthAck = 12&
Public Const RASCS_ReAuthenticate = 13&
Public Const RASCS_Authenticated = 14&
Public Const RASCS_PrepareForCallback = 15&
Public Const RASCS_WaitForModemReset = 16&
Public Const RASCS_WaitForCallback = 17&
Public Const RASCS_Projected = 18&

Public Const RASCS_Interactive = RASCS_PAUSED
Public Const RASCS_RetryAuthentication = RASCS_PAUSED + 1&
Public Const RASCS_CallbackSetByCaller = RASCS_PAUSED + 2&
Public Const RASCS_PasswordExpired = RASCS_PAUSED + 3&

Public Const RASCS_Connected = RASCS_DONE
Public Const RASCS_Disconnected = RASCS_DONE + 1&

' WINDOWS 95 ONLY - Intermediate states to a connection
Public Const RASCS_StartAuthentication = 19&
Public Const RASCS_CallbackComplete = 20&
Public Const RASCS_LogonNetwork = 21&

'*---------------------------------------------------------------
'* User-Defined Public Type Definitions
'* Note: VB subscripts are already +1 over C subscripts
'*---------------------------------------------------------------

Public Type RasDialExtensions  ' Describe extended connection establishment options
  dwSize      As Long  ' Set dwSize to 16
  dwfOptions  As Long
  hWndParent  As Long
  Reserved    As Long
End Type

Public Type RasDialParams  ' Describe connection establishment parameters
  dwSize                                   As Long  ' Set dwsize to 736 unless WINVER >= then set to 1052
  szEntryName(RAS_MaxEntryName)            As Byte
  szPhoneNumber(RAS_MaxPhoneNumber)        As Byte
  szCallBackNumber(RAS_MaxCallbackNumber)  As Byte
  szUserName(UNLEN)                        As Byte
  szPassword(PWLEN)                        As Byte
  szDomain(DNLEN)                          As Byte
End Type

Public Type RasDialParams95  ' Describe connection establishment parameters for WINDOWS 95
  dwSize                                     As Long  ' Set dwsize to 1052
  szEntryName(RAS95_MaxEntryName)            As Byte
  szPhoneNumber(RAS_MaxPhoneNumber)          As Byte
  szCallBackNumber(RAS95_MaxCallbackNumber)  As Byte
  szUserName(UNLEN)                          As Byte
  szPassword(PWLEN)                          As Byte
  szDomain(DNLEN)                            As Byte
End Type

Public Type RASConn  ' Identifies an active RAS Connection
  dwSize                        As Long  ' Set dwSzie to 32
  hRASConn                      As Long
  szEntryName(RAS_MaxEntryName) As Byte
End Type

Public Type RASConn95  ' Identifies an active RAS Connection for WINDOWS 95
  dwSize                             As Long  ' Set dwSzie to 412
  hRASConn                           As Long
  szEntryName(RAS95_MaxEntryName)    As Byte
  szDeviceType(RAS_MaxDeviceType)    As Byte
  szDeviceName(RAS95_MaxDeviceName)  As Byte
End Type

Public Type RASEntryName  ' Describes an enumerated RAS phone book entry name
  dwSize                         As Long  ' Set dwSize to 28 unless WINVER >= 400 then set to 264
  szEntryName(RAS_MaxEntryName)  As Byte
End Type

Public Type RASEntryName95  ' Describes an enumerated RAS phone book entry name for WINDOWS 95
  dwSize                           As Long  ' Set dwSize to 264
  szEntryName(RAS95_MaxEntryName)  As Byte
End Type

Public Type RASConnStatus  ' Describe the status of a RAS Connection
  dwSize                           As Long  ' Set dwSize to 64 unless WINVER >= 400 then set to 288
  RASConnState                     As Long  ' RASConnState enumeration
  dwError                          As Long
  szDeviceType(RAS_MaxDeviceType)  As Byte
  szDeviceName(RAS_MaxDeviceName)  As Byte
End Type

Public Type RASConnStatus95  ' Describe the status of a RAS Connection for WINDOWS 95
  dwSize                             As Long  ' Set dwSize to 160
  RASConnState                       As Long  ' RASConnState enumeration
  dwError                            As Long
  szDeviceType(RAS_MaxDeviceType)    As Byte
  szDeviceName(RAS95_MaxDeviceName)  As Byte
End Type

Public Type RASAMB  ' Describes the result of a RAS AMB (Authentication Message Block)
             ' projection.  This protocol is used with NT 3.1 and OS/2 1.3
             ' downlevel RAS servers
  dwSize                            As Long  ' Set dwSize to 28
  dwError                           As Long
  szNetBiosError(NETBIOS_NAME_LEN)  As Byte
  bLana                             As Byte
End Type

Public Type RASPPPNBF  ' Describes the result of a PPP NBF (NetBEUI) projection
  dwSize                               As Long  ' Set dwSize to 48
  dwError                              As Long
  dwNetBiosError                       As Long
  szNetBiosError(NETBIOS_NAME_LEN)     As Byte
  szWorkstationName(NETBIOS_NAME_LEN)  As Byte
  bLana                                As Byte
End Type

Public Type RASPPPIPX  ' Describes the results of a PPP IPX (Internetwork Packet Exchange) projection
  dwSize                           As Long  ' Set dwSize to 32
  dwError                          As Long
  szIpxAddress(RAS_MaxIPXAddress)  As Byte
End Type

Public Type RASPPPIP  ' Describes the result of a PPP IP (Internet Protocol) projection
  dwSize                             As Long  ' Set dwSize to 40
  dwError                            As Long
  szIPAddress(RAS_MaxIPAddress)      As Byte
  szServerAddress(RAS_MaxIPAddress)  As Byte
End Type

'*---------------------------------------------------------------
'* RAS DLL Function Declarations
'*---------------------------------------------------------------
Public Declare Function RasCreatePhonebookEntry Lib "RASAPI32" Alias "RasCreatePhonebookEntryA" ( _
  ByVal hWnd As Long, _
  ByVal lpszPhonebook As String _
) As Long

Public Declare Function RasDial Lib "RASAPI32" Alias "RasDialA" ( _
  lpRASDialExtensions As Any, _
  ByVal lpszPhonebook As String, _
  lpRASDialParams As Any, _
  ByVal dwNotifierType As Long, _
  lpvNotifier As Long, _
  lphRASConn As Long _
) As Long

Public Declare Function RasEditPhonebookEntry Lib "RASAPI32" Alias "RasEditPhonebookEntryA" ( _
  ByVal hWnd As Long, _
  ByVal lpszPhonebook As String, _
  ByVal lpszEntryName As String _
) As Long

Public Declare Function RasEnumConnections Lib "RASAPI32" Alias "RasEnumConnectionsA" ( _
  lpRASConn As Any, _
  lpcb As Long, _
  lpcConnections As Long _
) As Long

Public Declare Function RasEnumEntries Lib "RASAPI32" Alias "RasEnumEntriesA" ( _
  ByVal Reserved As String, _
  ByVal lpszPhonebook As String, _
  lpRASEntryName As Any, _
  lpcb As Long, _
  lpcEntries As Long _
) As Long

Public Declare Function RasGetConnectStatus Lib "RASAPI32" Alias "RasGetConnectStatusA" ( _
  ByVal hRASConn As Long, _
  lpRASConnStatus As Any _
) As Long

Public Declare Function RasGetEntryDialParams Lib "RASAPI32" Alias "RasGetEntryDialParamsA" ( _
  ByVal lpszPhonebook As String, _
  lpRASDialParams As Any, _
  lpfPassword As Long _
) As Long

Public Declare Function RasGetProjectionInfo Lib "RASAPI32" Alias "RasGetProjectionInfoA" ( _
  ByVal hRASConn As Long, _
  ByVal RASProjection As Long, _
  lpProjection As Any, _
  lpcb As Long _
) As Long

Public Declare Function RasHangUp Lib "RASAPI32" Alias "RasHangUpA" ( _
  ByVal hRASConn As Long _
) As Long

Public Declare Function RasSetEntryDialParams Lib "RASAPI32" Alias "RasSetEntryDialParamsA" ( _
  ByVal lpszPhonebook As String, _
  lpRASDialParams As Any, _
  ByVal fRemovePassword As Long _
) As Long

'*---------------------------------------------------------------
'* Public Variables
'*---------------------------------------------------------------
Public arrPEntry() As clsPhoneEntry
Public arrConnection() As clsConnection

Public lpConnections As clsConnections
Public lpPhoneEntries As clsPhoneEntries

Public blnAllowUpdate As Boolean

Public strCurrentEntryName As String

'*---------------------------------------------------------------
'* EOF: basRAS
'*---------------------------------------------------------------
